#include<stdio.h>

struct student
   {
       int id;
       char *name;
       char gender;
       int age;
   };

int asc(struct student stu1,struct student stu2){
	return stu1.id > stu2.id; 
}

int desc(struct student stu1,struct student stu2){
 	return stu1.id < stu2.id;
}

void sort(struct student *stu, int len, int(*func)(struct student,struct student)){
	for(int i=0; i<len-1; i++){
		int flag = 0;
		for(int j=0; j<len-1-i; j++){
			if(func(stu[j],stu[j+1])){
				flag = 1;	
				struct student temp = stu[j];
				stu[j] = stu[j+1];
				stu[j+1] = temp;
			}
		}
		if(!flag){
			break;
		}
	}

}


void show(const struct student* stu){
    printf("学号：%d, 姓名：%s, 性别：%c, 年龄：%d\n",
            stu->id,
            stu->name,
            stu->gender,
            stu->age);
}

int main()
{
	struct student stu[] = {
              {10002,"俞莲舟",'M',45},
			  {10001,"宋远桥",'M',50},
              {10005,"张翠山",'M',36},
			  {10003,"俞岱岩",'M',42},
              {10006,"殷梨亭",'M',32},
			  {10004,"张松溪",'M',40},
              {10007,"莫声谷",'M',30}
            };
	sort(stu,7,asc);
	for(int i=0; i<7; i++){
		show(&stu[i]);
	}
	printf("-----------------------------------------\n");
	sort(stu,7,desc);
	for(int i=0; i<7; i++){
		show(&stu[i]);
	}
}
